<?php

use think\migration\Migrator;
use think\migration\db\Column;

class StoreUserCredit extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('store_user_credit', ['comment' => '用户账单表'])
             ->addColumn('store_id', 'integer', ['limit' => 11, 'default' => '0', 'after' => "id", 'comment' => '店铺id'])
             ->addColumn('store_user_id', 'integer', ['limit' => 11, 'default' => '0', 'after' => "store_id", 'comment' => '用户ID'])
             ->addColumn('store_order_id', 'integer', ['limit' => 11, 'default' => '0', 'after' => "store_user_id", 'comment' => '订单ID'])
             ->addColumn('type', 'integer', ['limit' => 1, 'default' => '1', 'after' => "store_order_id", 'comment' => '类型： 1:信用消费'])
             ->addColumn('pay_status', 'integer', ['limit' => 1, 'default' => '1', 'after' => "type", 'comment' => '支付状态： 1:未支付 ,2:已支付'])
             ->addColumn('pay_time', 'integer', ['limit' => 10, 'default' => '0', 'after' => "pay_status", 'comment' => '支付时间'])
             ->addColumn('credit_time', 'integer', ['limit' => 10, 'default' => '0', 'after' => "pay_time", 'comment' => '出账时间'])
             ->addColumn('credit_amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'after' => "credit_time", 'comment' => '账单金额'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => '1', 'after' => "credit_amount", 'comment' => '状态： 1:未出账单 ,2:已出账单'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->create();
    }
}
